import pygame
from pygame.sprite import spritecollideany, Sprite, Group
from multipledispatch import dispatch


@dispatch(Group, Group)
def check_collision(bullets: object, aliens: object) -> None:
    """检测子弹和外星人碰撞使用 groupcollide() 方法
    检测到碰撞后，删除子弹和外星人，并且利用返回的字典 collisions_dict 储存碰撞的子弹和外星人
    :param bullets: 子弹编组
    :param aliens: 外星人编组
    """
    collisions_dict = pygame.sprite.groupcollide(bullets, aliens, True, True)

@dispatch(Sprite, Group)
def check_collision(ship: Sprite, aliens: object) -> bool:
    if spritecollideany(ship, aliens):
       ship.kill()
       print('ship is dead')
       return True

    return False